﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NS_Client
{
    public partial class LoginForm : NS_UI
    {
        ///// <summary>The LoginController associated with this LoginForm instance</summary>
        LoginController LoginFormController;
       
        public LoginForm()
        {
            InitializeComponent();
        }

        /// <summary>Sets the LoginController associated with this LoginForm instance</summary>
        public override void SetListener(ViewController controller)
        {
            this.LoginFormController = (LoginController)controller;
        }

        /// <summary>Notifies the form to update based of new state</summary>
        /// <param name="Data">The data used to update the form</param>
        public override void notify(object Data)
        {
            SessionModel SessionData = (SessionModel)Data;
            if (SessionData.FailedReason != "")
            {
                lblError.Visible = true;
                lblErrReason.Text = SessionData.FailedReason;
            }
        }

        private void LoginForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            LoginFormController.CloseView();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            LoginFormController.LogIn(txtUsername.Text, txtPassword.Text);
        }
    }
}
